﻿@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_Form.cshtml";
}


<form id="form1">
    <div style="padding-top: 20px; margin-right: 30px; ">
        <table class="form">
            <tr>
                <td class="formTitle"><span class="required">*</span>组织机构：</td>
                <td class="formValue formDdlSelectorTd">
                    <select id="OrganizeId" name="OrganizeId" class="form-control required">
                        <option value="">==请选择==</option>
                    </select>
                </td>
                <td class="formTitle"><span class="required">*</span>名称：</td>
                <td class="formValue">
                    <input id="sfxmmc" name="sfxmmc" type="text" class="form-control required" />
                </td>
                <td class="formTitle"><span class="required">*</span>编码：</td>
                <td class="formValue">
                    <input id="sfxmCode" name="sfxmCode" type="text" class="form-control required" placeholder="请输入编码" />
                </td>
            </tr>
            <tr id="trSSDJ" name="trSSDJ">
                <th class="formTitle"><span class="required">*</span>首拼：</th>
                <td class="formValue">
                    <input id="py" name="py" type="text" class="form-control required" placeholder="" />
                </td>
                <th class="formTitle">手术等级：</th>
                <td class="formValue">
                    <select id="ssdj" name="ssdj" class="form-control required">
                        <option value="">==请选择==</option>
                        <option value="1">一级手术</option>
                        <option value="2">二级手术</option>
                        <option value="3">三级手术</option>
                        <option value="4">四级手术</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td class="formTitle">
                    <span class="required">*</span>自负性质：
                </td>
                <td class="formValue">
                    @Html.DropDownList("zfxz", Newtouch.Infrastructure.EnumZFXZv2.ZF.ToDescSelectList(), "==请选择==", new { @class = "form-control required" })
                </td>
                <td class="formTitle">自负比例：</td>
                <td class="formValue">
                    <input id="zfbl" name="zfbl" type="text" class="form-control" placeholder="" />
                </td>
                <td class="formTitle">计价策略：</td>
                <td class="formValue">
                    @Html.DropDownList("jjcl", Newtouch.Infrastructure.EnumSfxmJjcl.Amount.ToDescSelectList(((int)Newtouch.Infrastructure.EnumSfxmJjcl.Amount)), "==请选择==", new { @class = "form-control required" })
                </td>
            </tr>
            <tr>
                <td class="formTitle"><span class="required">*</span>单价：</td>
                <td class="formValue">
                    <input id="dj" name="dj" type="text" class="form-control required" placeholder="" />
                </td>
                <td class="formTitle"><span class="required">*</span>单位：</td>
                <td class="formValue">
                    <input id="dw" name="dw" type="text" class="form-control required" placeholder="" />
                </td>
                <td class="formTitle">单位计量数：</td>
                <td class="formValue">
                    <input id="dwjls" name="dwjls" type="text" class="form-control" value="1" placeholder="" />
                </td>
            </tr>
            <tr>
                <td class="formTitle"><span class="required">*</span>收费大类：</td>
                <td class="formValue formDdlSelectorTd">
                    <select id="sfdlCode" name="sfdlCode" class="form-control required">
                        <option value="">==请选择==</option>
                    </select>
                </td>
                <td class="formTitle">病案收费大类：</td>
                <td class="formValue formDdlSelectorTd">
                    <select id="badlCode" name="badlCode" class="form-control">
                        <option value="">==请选择==</option>
                    </select>
                </td>
                <td class="formTitle">默认执行科室：</td>
                <td class="formValue formDdlSelectorTd">
                    <select id="zxks" name="zxks" class="form-control">
                        <option value="">==请选择==</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td class="formTitle">批准文号：</td>
                <td class="formValue" style="padding-top: 1px;">
                    <input id="pzwh" name="pzwh" type="text" class="form-control" placeholder="" />
                </td>
                <th class="formTitle">规格：</th>
                <td class="formValue">
                    <input id="gg" name="gg" type="text" class="form-control" placeholder="" />
                </td>
                <td class="formTitle">生产厂家：</td>
                <td class="formValue">
                    <input id="sccj" name="sccj" type="text" class="form-control" placeholder="" />
                </td>
            </tr>
            <tr>
                <td class="formTitle"><span class="required">*</span>医保标志：</td>
                <td class="formValue" style="padding-top: 1px;">
                    <div class="ckbox">
                        <!-- 医保标志：即便有医保代码对照，也需要打上医保标志才会跟医保交互 -->
                        <select id="ybbz" name="ybbz" class="form-control required">
                            <option value="">==请选择==</option>
                            <option value="1">是</option>
                            <option value="0">否</option>
                        </select>
                    </div>
                </td>
                <td class="formTitle">国家医保代码：</td>
                <td class="formValue">
                    <input id="gjybdm" name="gjybdm" type="text" class="form-control" placeholder="" />
                </td>
                <td class="formTitle">省医保代码：</td>
                <td class="formValue">
                    <!-- 从医保诊疗项目智能带出来的，医保分诊疗项目和材料 -->
                    <input id="ybdm" name="ybdm" type="text" class="form-control" placeholder="" />
                </td>
            </tr>
            <tr>
                @*<td class="formTitle">新农合医保代码：</td>
        <td class="formValue">
            <input id="xnhybdm" name="xnhybdm" type="text" class="form-control" placeholder="" />
        </td>*@
                <td class="formTitle"><span class="required">*</span>门诊住院标志：</td>
                <td class="formValue formDdlSelectorTd">
                    <select id="mzzybz" class="form-control required" name="mzzybz">
                        <option value="">==请选择==</option>
                        <option value="0">通用</option>
                        <option value="1">门诊</option>
                        <option value="2">住院</option>
                    </select>
                </td>
                <td class="formTitle" style="display:none">农保收费大类：</td>
                <td class="formValue formDdlSelectorTd" style="display:none">
                    <select id="nbdlCode" name="nbdlCode" class="form-control">
                        <option value="">==请选择==</option>
                    </select>
                </td>
                <td class="formTitle">医保限价：</td>
                <td class="formValue">
                    <input id="cxjje" name="cxjje" type="text" class="form-control" placeholder="" oninput="value=value.replace(/[^\d]/g,'')" />
                </td>
                <td class="formTitle">国家医保名称：</td>
                <td class="formValue">
                    <input id="gjybmc" name="gjybmc" type="text" class="form-control" placeholder=""/>
                </td>
            </tr>
            <tr>
                <td class="formTitle">实施标志：</td>
                <td class="formValue" style="padding-top: 1px;">
                    <div class="ckbox">


                        <input id="ssbz" name="ssbz" type="checkbox" checked="checked"><label for="ssbz">是</label>
                    </div>
                </td>
                <td class="formTitle">特殊标志：</td>
                <td class="formValue" style="padding-top: 1px;">
                    <div class="ckbox">
                        <!-- 特殊项目：1：xt_sfxmtsbz里配置的特殊病人群才可以使用该项目 -->
                        <input id="tsbz" name="tsbz" type="checkbox"><label for="tsbz">是</label>
                    </div>
                </td>
                <td class="formTitle">收费标志：</td>
                <td class="formValue" style="padding-top: 1px;">
                    <div class="ckbox">
                        <input id="sfbz" name="sfbz" type="checkbox" checked="checked"><label for="sfbz">是</label>
                    </div>
                </td>
            </tr>
            <tr>
                <th class="formTitle">申请类型：</th>
                <td class="formValue">
                    <select id="sqlx" name="sqlx" class="form-control">
                        <option value="">==请选择==</option>
                    </select>
                </td>
                <td class="formTitle">物价代码：</td>
                <td class="formValue">
                    <!-- 从医保诊疗项目智能带出来的，医保分诊疗项目和材料 -->
                    <input id="wjdm" name="wjdm" type="text" class="form-control" placeholder="" />
                </td>
                <td class="formTitle">时长（分）：</td>
                <td class="formValue">
                    <input id="duration" name="duration" type="text" class="form-control" placeholder="" />
                </td>
            </tr>
            <tr>
                <th class="formTitle">排序：</th>
                <td class="formValue">
                    <input id="px" name="px" type="text" class="form-control" placeholder="" />
                </td>
                <th class="formTitle" style="height: 35px;">状态：</th>
                <td class="formValue" style="padding-top: 1px;">
                    <div class="ckbox">
                        <input id="zt" name="zt" type="checkbox" checked="checked"><label for="zt">有效</label>
                    </div>
                </td>
            </tr>
            <tr>
                <th class="formTitle" valign="top" style="padding-top: 5px;">
                    备注：
                </th>
                <td class="formValue">
                    <textarea id="bz" name="bz" class="form-control" style="height: 60px;"></textarea>
                </td>
            </tr>
        </table>
    </div>
</form>

<script>
    var keyValue = $.request("keyValue");
    $(function () {
        initControl();
        
        if (!!keyValue) {
            $.najax({
                url: "/SysChargeItem/GetFormJson",
                data: { keyValue: keyValue },
                dataType: "json",
                async: false,
                success: function (data) {
                    $("#form1").formSerialize(data);

                    $("#OrganizeId").trigger('change');

                    $("#sfdlCode").val(data.sfdlCode).trigger('change');
                    $("#badlCode").val(data.badlCode).trigger('change');
                    $("#nbdlCode").val(data.nbdlCode).trigger('change');
                    $("#zxks").val(data.zxks).trigger('change');
                    $("#cxjje").val(data.cxjje);
                }
            });
        }
        else {
            var newOrgId = $.request('orgId');
            if (newOrgId) {
                $("#OrganizeId").val(newOrgId).trigger('change');
            }
        }
    });

    function initControl() {
        //组织机构下拉框
        $("#OrganizeId").bindSelect({
            url: "/Organize/GetChildTreeSelectJson",
        });
        //组织对应的科室下拉框加载
        $("#OrganizeId").bind("change", function () {
            var organizeId = $(this).val();
            //获取收费大类
            $("#sfdlCode").bindSelect({
                url: "/ChargeCategory/GetTreeSelectJson?organizeId=" + organizeId,
            });
            //获取病案收费大类
            $("#badlCode").bindSelect({
                url: "/SysMedicalRecordChargeCategory/GetListSelectJson?organizeId=" + organizeId,
                id: "dlCode",
                text: "dlmc",
            });
            //获取农保收费大类
            $("#nbdlCode").bindSelect({
                url: "/SysAgriInsuranceChargeCategory/GetListSelectJson?organizeId=" + organizeId,
                id: "dlCode",
                text: "dlmc",
            });
            //默认执行科室
            $("#zxks").bindSelect({
                url: "/Department/GetTreeSelectJson?organizeId=" + organizeId,
            });
        });
        $('#zfxz').select2();
        //首拼
        $('#sfxmmc').keyup(function () {
            $('#py').val($(this).toShouPin());
        });
        //药品申请类型
        $("#sqlx").bindSelect({
            url: "/ItemsData/GetSelectJson",
            param: { code: "ExamTypeID" }
        });
        //$("#sfxmmc").ypFloatingSelector({
        //    itemdbclickhandler: function ($thistr) {
        //        $('#id').val($thistr.attr('data-id'));
        //        $('#xmmc').val($thistr.attr('data-xmmc'));
        //        $('#pym').val($thistr.attr('data-pym'));
        //        $('#ybxj').val($thistr.attr('data-ybxj'));
        //        $('#dfybdm').val($thistr.attr('data-dfybdm'));
        //        $('#gjybdm').val($thistr.attr('data-gjybdm'));
        //    }
        //});

        $.fn.sfxmmcFloatingSelector = function (options) {
            var defaults = {
                url: '/SysMedicine/GetYbName',
                width: 1100,
                height: 300,
                clickautotrigger: true,
                caption: "选择药品",
				ajaxparameters: function ($thisinput) {
					var key = $.trim($('#sfxmmc').val());
					if ($thisinput.selector == "#gjybdm") {
                        key = $.trim($('#gjybdm').val());;
					}
                    return 'organizeId=' + $.trim($('#OrganizeId').val()) + '&keyword=' + key + '&lx=' + $("#sfdlCode").val();
                },
                itemdbclickhandler: null,
                colModel: [
                    { label: '类型', name: 'lx', widthratio: 5, },
                    { label: '国家项目名称', name: 'xmmc', widthratio: 15 },
                    { label: '国家医保代码', name: 'gjybdm', widthratio: 15, },
                    { label: '规格', name: 'gg', widthratio: 5, },
                    { label: '单位', name: 'dw', widthratio: 5, },
                    { label: '单价', name: 'dj', widthratio: 5, },
                    { label: '医保限价', name: 'ybxj', widthratio: 10 },
                    { label: '批准文号', name: 'pzwh', widthratio: 10, },
                    { label: '生产厂家', name: 'sccj', widthratio: 10, },
                    { label: '项目名称', name: 'dfxmmc', widthratio: 10, },
                    { label: '医保代码', name: 'dfybdm', widthratio: 10 },
                    { label: '拼音码', name: 'pym', widthratio: 10, hidden: true },
                    { label: 'ID', name: 'id', widthratio: 5, hidden: true },
                ]
            };
            var options = $.extend(defaults, options);

            $(this).newtouchFloatingSelector(options);
        }

        $("#sfxmmc").sfxmmcFloatingSelector({
            organizeId: $.trim($('#OrganizeId').val()),
            width: 700,
            
            itemdbclickhandler: function ($thistr) {
                var curData = $.currentWindow().document.getElementById('gridList');
                var rowIds = jQuery(curData).jqGrid('getDataIDs');
                for (var k = 0; k < rowIds.length; k++) {
                    debugger
                    var curRowData = jQuery(curData).jqGrid('getRowData', rowIds[k]);
                    if ($thistr.attr('data-gjybdm') != "" && $thistr.attr('data-gjybdm') != null && curRowData.gjybdm == $thistr.attr('data-gjybdm')) {
                        $.modalAlert("系统已存在国家医保代码为" + $thistr.attr("data-gjybdm") + "的药品，" + $thistr.attr("data-xmmc"), 'warning');
                    };
                    $('#py').val($thistr.attr('data-pym'));
                    $('#sfxmmc').val($thistr.attr('data-xmmc'));
                    $('#cxjje').val($thistr.attr('data-ybxj'));
                    $('#ybdm').val($thistr.attr('data-dfybdm'));
                    $('#gjybdm').val($thistr.attr('data-gjybdm'));
                    $('#ybbz').val("1");
                }
            }
		});

		$("#gjybdm").sfxmmcFloatingSelector({
			organizeId: $.trim($('#OrganizeId').val()),
			width: 1100,
			itemdbclickhandler: function ($thistr) {
				var curData = $.currentWindow().document.getElementById('gridList');
				var rowIds = jQuery(curData).jqGrid('getDataIDs');
				for (var k = 0; k < rowIds.length; k++) {
					debugger
					var curRowData = jQuery(curData).jqGrid('getRowData', rowIds[k]);
					//if ($thistr.attr('data-gjybdm') != "" && $thistr.attr('data-gjybdm') != null && curRowData.gjybdm == $thistr.attr('data-gjybdm')) {
					//	$.modalAlert("系统已存在国家医保代码为" + $thistr.attr("data-gjybdm") + "的药品，" + $thistr.attr("data-xmmc"), 'warning');
					//};
				}
                if (($('#sfxmmc').val() != "" || $('#ypmc').val() != null) && $('#ybdm').val() != $thistr.attr('data-gjybdm')) {
					$.modalConfirm("是否更新当前项目医保信息？", function (flag) {
						if (flag) {
							//$('#py').val($thistr.attr('data-pym'));
							//$('#sfxmmc').val($thistr.attr('data-xmmc'));
							$('#cxjje').val($thistr.attr('data-ybxj'));
							$('#ybdm').val($thistr.attr('data-dfybdm'));
							$('#gjybdm').val($thistr.attr('data-gjybdm'));
							$('#ybbz').val("1");
                            $('#sccj').val($thistr.attr('data-sccj'));
                            $('#gg').val($thistr.attr('data-gg'));
                            $('#pzwh').val($thistr.attr('data-pzwh'));
                            $('#gjybmc').val($thistr.attr('data-xmmc'));
						}
					})
				}
			}
		});

    }
    

    var anPrevOrg = null;
    $('#sfxmCode').focus(function () {
        var organizeId = $("#OrganizeId").val();
        if (!!!keyValue && ($.trim($(this).val()) === '' || organizeId != anPrevOrg)) {
            anPrevOrg = organizeId;
            $.najax({
                url: "/HOME/GetNewFieldUniqueValue?topOrgIdIsStar=false&initFieldLength=8&fieldName=xt_sfxm.sfxmCode&orgId=" + organizeId + "&r=" + Math.random(),
                dataType: "json",
                cache: false,
                success: function (data) {
                    $('#sfxmCode').val(data.data);
                }
            });
        }
        });
        

    function submitForm() {
        if (!$('#form1').formValid()) {
            return false;
        }
        debugger
        var postData = $("#form1").formSerialize();
        $.submitForm({
            url: "/SysChargeItem/SubmitForm?keyValue=" + keyValue,
            param: postData,
            success: function () {
                $.currentWindow().$("#gridList").resetSelection();
                $.currentWindow().$("#gridList").trigger("reloadGrid");
            }
        })
    }

    $("#sfdlCode").change(function () {
        if ($("#sfdlCode").val() == "13") {
            $("#ssdj").addClass("form-control required");
            $("#trSSDJ").css("display", "");
        }
        else {
            $("#ssdj").removeClass("required");
            $("#ssdj").val("");
            $("#trSSDJ").css("display", "none");
        }
    });


</script>